<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">

  <!-- Copy all attributes and elements to the output. -->
  <xsl:template match="@*|*">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:apply-templates select="*" />
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="wix:Wix">
    <xsl:copy>
      <xsl:processing-instruction name="include">$(var.ProjectDir)defines.wxi</xsl:processing-instruction>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>
  
  <xsl:output method="xml" indent="yes" />

  <!-- Search directories for the components that will be removed. -->
  <xsl:key name="exe-search" match="wix:Component['Red.Scripts.Shell.exe' = substring( wix:File/@Source, string-length( wix:File/@Source ) - string-length( 'Red.Scripts.Shell.exe' ) + 1 )]" use="@Id"/>
  <xsl:key name="pdb-search" match="wix:Component[contains(wix:File/@Source, '.pdb')]" use="@Id"/>
  <xsl:key name="dll-config-search" match="wix:Component[contains(wix:File/@Source, '.dll.config')]" use="@Id"/>
  <xsl:key name="vshost-search" match="wix:Component[contains(wix:File/@Source, '.vshost.exe')]" use="@Id"/>
  <xsl:key name="ilk-search" match="wix:Component[contains(wix:File/@Source, '.ilk')]" use="@Id"/>

  <!-- Remove components/refs referencing components in those directories. -->
  <xsl:template match="wix:Component[key('exe-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('exe-search', @Id)]" />
  <xsl:template match="wix:Component[key('pdb-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('pdb-search', @Id)]" />
  <xsl:template match="wix:Component[key('dll-config-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('dll-config-search', @Id)]" />
  <xsl:template match="wix:Component[key('vshost-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('vshost-search', @Id)]" />
  <xsl:template match="wix:Component[key('ilk-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('ilk-search', @Id)]" />
  
  <xsl:template match="@type[parent::property]" />
</xsl:stylesheet>